<template>
<van-icon color="#dada1f" name="good-job-o" v-if="value!=-1" @click="onCollect" />
<van-icon color="#777" name="good-job-o" v-else @click="onCollect" />
</template>

<script>
import { deleteLike, like } from '@/api/article'
export default {
  props: {
    value: {
      type: Number,
      required: true
    },
    art_id: {
      type: [Number, String, Object],
      required: true
    }
  },
  data () {
    return {

    }
  },
  methods: {
    async onCollect () {
      try {
        if (this.value === -1) {
          await like(this.art_id)
        } else {
          await deleteLike(this.art_id)
        }
      } catch (err) {
      }
      let info
      if (this.value === -1) {
        info = '点赞成功'
      } else {
        info = '取消点赞成功'
      }
      this.$toast.success(info)
      this.$emit('input', this.value === -1 ? 1 : -1)
    }
  }
}
</script>

<style scoped lang="less">

</style>
